package javaBase.nowcoder.HJ101_B_输入整型数组和排序标识_对其元素按照升序或降序进行排序;

import java.io.*;
import java.util.Arrays;

public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String n = br.readLine();
        String val = br.readLine();
        String flag = br.readLine();
        StringBuilder result = new StringBuilder();
        Arrays.asList(val.trim().split(" ")).stream().map(Integer::valueOf).sorted((o1, o2) -> {
            if ("0".equals(flag.trim())) {
                return o1 - o2;
            } else if ("1".equals(flag.trim())) {
                return o2 - o1;
            }
            return 0;
        }).forEach(integer -> {
            result.append(integer + " ");
        });
        System.out.println(result.toString().trim());


    }
}
